package com.cs.user.application.controller;

import com.cs.user.application.dtos.RoleDTO;
import com.cs.user.application.dtos.UserRoleDTO;
import com.cs.user.common.entity.BaseResponse;
import com.cs.user.common.utlis.ResultUtils;
import com.cs.user.domain.bos.UserRoleBO;
import com.cs.user.domain.service.UserRoleDomainService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/user/role")
public class UserRoleController {

    @Resource
    private UserRoleDomainService userRoleDomainService;

    @PostMapping("/add")
    public BaseResponse<Boolean> addUserRole(@RequestBody UserRoleDTO userRoleDTO){
        // 输出日志
        log.info("添加用户角色关系表请求参数：{}", userRoleDTO);
        // 类型转换
        UserRoleBO userRoleBO = new UserRoleBO();
        BeanUtils.copyProperties(userRoleDTO, userRoleBO);
        // 调用domain层方法
        return ResultUtils.success(userRoleDomainService.addUserRole(userRoleBO));
    }
}
